package Json2RDF.Surface2RDF.SurfaceWriter;

import Json2RDF.Json2Java.OntologyClasses.b_conicalSurface;
import Json2RDF.Surface2RDF.IndexTable.FaceIndexTable;
import Json2RDF.Surface2RDF.IndexTable.Face2ResourceIndexTable;
import RDFManager.PropertySet;
import RDFManager.RDFHead;
import RDFManager.RDFReader;
import RDFManager.ResourceSet;

import java.util.List;
import java.util.stream.IntStream;

import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.RDF;

/**
 * {@code b_conicalSurfaceWriter}类提供将Conical_Surface写入RDF文件的方法.
 */
public class b_conicalSurfaceWriter {

    /**
     * 遍历List中每个元素，将其对应数据属性值写入RDF文件，并添加到HashMap中.
     *
     * @param b_conicalSurfaceList 待写入的b_Conical_Surface列表
     */
    public static void writeList(List<b_conicalSurface> b_conicalSurfaceList) {
        IntStream.range(0, b_conicalSurfaceList.size()).forEach(i -> {
            write(b_conicalSurfaceList.get(i), "b_conicalSurface" + (i + 1));
            Face2ResourceIndexTable.faceResourceIdxTbl.computeIfAbsent(b_conicalSurfaceList.get(i), v -> RDFReader.model.getResource(RDFHead.namespace + "b_conicalSurface" + (i + 1)));
            FaceIndexTable.faceIdxTbl.computeIfAbsent(b_conicalSurfaceList.get(i).getId(), v -> b_conicalSurfaceList.get(i));
        });
    }

    private static void write(b_conicalSurface b_conicalSurface, String name) {
        Resource inst = RDFReader.model.createResource(RDFHead.namespace + name);
        RDFReader.model.add(inst, RDF.type, ResourceSet.Face);
        RDFReader.model.add(inst, RDF.type, ResourceSet.b_conicalSurface);
        inst.addLiteral(PropertySet.hasID, b_conicalSurface.getId());
        inst.addLiteral(PropertySet.hasTopRadius, b_conicalSurface.getTopRadius());
        inst.addLiteral(PropertySet.hasBottomRadius, b_conicalSurface.getBottomRadius());
        RDFTripleArrayWriter.writeTripleArray(inst, "hasAxisEnd1", b_conicalSurface.getAxisEnd1());
        RDFTripleArrayWriter.writeTripleArray(inst, "hasAxisEnd2", b_conicalSurface.getAxisEnd2());
        inst.addLiteral(PropertySet.hasHeight, b_conicalSurface.getHeight());
    }
}
